package gov.nhso.prov.acc.utils;

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class DigitUtil {
	public String numberFormat(String format, String number) {
		String result = "";
        try {
        	if (number != null && !number.equals("")) {
	        	NumberFormat formatter = new DecimalFormat(format);
	        	result = formatter.format(Double.parseDouble(number.replaceAll("[^.0-9\\-]+", "")));
        	}
        } catch (Exception e) {
        	e.printStackTrace();
		}
        return result;
	}
	public String formatDecimal(double d, int precision){
		String myformat = "###,###,###,###,##0";
		if (precision == 0){
			DecimalFormat df = new DecimalFormat(myformat);
			return df.format(d);
		}
		myformat = "###,###,###,###,##0.";

		for(int x= 0; x < precision; x++)
		myformat = myformat + "0";

		DecimalFormat df = new DecimalFormat(myformat);
		return df.format(d);
	}
}
